Skip to content

AD rules for (anti-) hermitian projection#174

Open
lkdvos wants to merge 9 commits intomainfrom
hermitian
Open

AD rules for (anti-) hermitian projection#174
lkdvos wants to merge 9 commits intomainfrom
hermitian

Conversation

@lkdvos
Copy link
Member

@lkdvos lkdvos commented Feb 17, 2026

Fixes #99.

I played around a bit with also implementing the project_isometric, but since that was taking more significant changes (possibly writing an actual sylvester equation solver), I will leave that for a follow-up.
Also, I'm not actually smart enough for Enzyme rules, so will also ignore that for now. (Additionally I'm not sure we need them in that case, so don't want to pollute this PR)

lkdvos and others added 8 commits February 14, 2026 16:11
Guard `C .+= ΔP` with `!iszerotangent(ΔP)` in both
`left_polar_pullback!` and `right_polar_pullback!` to handle
the case where ΔP is `nothing`.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace LAPACK trsyl!-based solver with a direct eigendecomposition
approach when both arguments are the same Hermitian matrix (as in polar
pullbacks). This avoids LAPACKException(1) for close eigenvalues.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add rrules/pullbacks for `project_hermitian!`, `project_antihermitian!`,
and `project_isometric!` directly in each AD backend extension
(ChainRulesCore, Enzyme, Mooncake). The hermitian/antihermitian
pullbacks are self-adjoint, while the isometric pullback delegates to
`left_polar_pullback!` with zero ΔP.

Includes test utilities and tests for all three backends.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@lkdvos lkdvos requested review from Jutho and kshyatt February 17, 2026 15:20
Copy link
Member

@Jutho Jutho Feb 18, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should I think of this if dA === darg?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also wondering if we can use a more general operation than broadcasted .+= to add f(darg) into dA. Has Mooncake a dedicated add! for tangents? Or do we start using VectorInterface.jl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Has Mooncake a dedicated add! for tangents?

Isn't that increment!!?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would make me hesitate to use increment!! is that this has already been arrayify'd, so therefore it's not entirely clear to me anymore what kind of object/guarantees on the interface we still have. In any case I'd be happy to pull in more VectorInterface methods, I do think there are some places here and there where it might make sense in any case, and reducing the number of functions seems useful

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This being said, I do agree this rule looks off, and I'm worried about the tests not capturing this. I'll try and have a look at the in-place testing facilities and see if I can make this fail somehow

@codecov
Copy link

codecov bot commented Feb 19, 2026

Codecov Report

❌ Patch coverage is 91.89189% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...gebraKitMooncakeExt/MatrixAlgebraKitMooncakeExt.jl 86.95% 3 Missing ⚠️
Files with missing lines Coverage Δ
ext/MatrixAlgebraKitChainRulesCoreExt.jl 83.33% <100.00%> (+1.19%) ⬆️
src/pullbacks/polar.jl 100.00% <100.00%> (ø)
...gebraKitMooncakeExt/MatrixAlgebraKitMooncakeExt.jl 61.97% <86.95%> (+1.21%) ⬆️

... and 1 file with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[AD] rrules for project_(anti)hermitian

3 participants

Comments